package flex.cc.basicinformation.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;

import flex.cc.PublicUtil;
import flex.cc.base.dto.LoginAuthDto;
import flex.cc.basicinformation.entity.ServiceProviderEntity;
import flex.cc.basicinformation.service.ServiceProviderService;
import flex.cc.basicinformation.vo.ServiceProviderVo;
import flex.cc.core.annotation.LogAnnotation;
import flex.cc.core.annotation.ValidateAnnotation;
import flex.cc.core.support.BaseController;
import flex.cc.wrapper.WrapMapper;
import flex.cc.wrapper.Wrapper;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 权限表
 *
 * @author guozejun
 * @email guozejun@sinosoft.com.cn
 * @date 2021-10-14 22:29:37
 */
@RestController
@RequestMapping(value = "/basic/information")
public class ServiceProviderController extends BaseController {

    @Resource
    private ServiceProviderService facilitatorService;

    /**
     * 分页查询渠道信息.
     */
    @PostMapping(value = "/queryServiceProviderPage")
    @ApiOperation(httpMethod = "POST", value = "查询渠道商基本信息")
    public Wrapper<IPage<ServiceProviderEntity>> queryServiceProviderPage(@ApiParam(name = "flex", value = "渠道信息") @RequestBody ServiceProviderEntity flex) {
        logger.info("查询渠道商基本信息queryChannel={}", flex);
        IPage<ServiceProviderEntity> page = facilitatorService.queryServiceProviderPage(flex);
        return WrapMapper.ok(page);
    }

    /**
     * 保存救援商信息
     */
    @PostMapping(value = "/saveServiceProvider")
    @ApiOperation(httpMethod = "POST", value = "新增/编辑救援商信息")
    @ValidateAnnotation
    @LogAnnotation
    public Wrapper saveFacilitator(@ApiParam(name = "action", value = "救援商信息") @RequestBody ServiceProviderEntity service) {
        LoginAuthDto loginAuthDto = this.getLoginAuthDto();
        facilitatorService.saveServiceProvider(service, loginAuthDto);
        return WrapMapper.ok();
    }

    @GetMapping(value = "/getServiceName/{serviceName}/{id}")
    @ApiOperation(httpMethod = "GET", value = "查询服务商名称是否重复")
    public Wrapper<String> getServiceName(@PathVariable(value = "serviceName") String serviceName, @PathVariable(value = "id") String id) {
    	String result=facilitatorService.getServiceName(serviceName, id);
    	return WrapMapper.ok(result);
    }
    @GetMapping(value = "/getServiceCode/{serviceCode}/{id}")
    @ApiOperation(httpMethod = "GET", value = "查询服务商code是否重复")
    public Wrapper<String> getServiceCode(@PathVariable(value = "serviceCode") String serviceCode, @PathVariable(value = "id") String id) {
    	String result=facilitatorService.getServiceCode(serviceCode, id);
    	return WrapMapper.ok(result);
    }
    @PostMapping(value = "/getAllServiceName")
    @ApiOperation(httpMethod = "POST", value = "查询服务商信息")
    public Wrapper<List<ServiceProviderEntity>> getAllServiceInfo() {
        List<ServiceProviderEntity> list = facilitatorService.getAllServiceName();
        return WrapMapper.ok(list);
    }

    /**
     * @description 启用救援商【2.2-服务包配置需求】
     * @param id 救援商主键
     * @param status 目标状态
     * @return
     * @author wkangle
     * @time 2022/02/23 0023 18:08
     * @exception/throws
     */
    @LogAnnotation
    @GetMapping(value = "/serviceProvider/switchStatus/{id}/{status}")
    @ApiOperation(httpMethod = "GEt", value = "救援商状态修改")
    public Wrapper<Map<String, String>> switchStatus(@ApiParam(name = "reqVo", value = "请求信息") @PathVariable(value = "id") Long id, @PathVariable(value = "status") String status) {
        Map<String, String> switchStatus = facilitatorService.switchStatus(id, status);
        return WrapMapper.ok(switchStatus);
    }

    /**
     * @param id 救援商主键id
     * @return
     * @description 根据救援商主键id查询一个，用于修改页面回显【2.2-服务包配置需求】
     * @author wkangle
     * @time 2022-03-03 14:08:33
     * @exception/throws
     */
    @GetMapping(value = "/serviceProvider/queryOne/{id}")
    @ApiOperation(httpMethod = "GET", value = "查询一个用于修改")
    public Wrapper<ServiceProviderVo> queryOne(@ApiParam(name = "action", value = "救援商id") @PathVariable(value = "id") Long id) {
        logger.info("{} /serviceProvider/queryOne ==> {}", new Date(), id);
        ServiceProviderVo vo = facilitatorService.queryOne(id);
        return WrapMapper.ok(vo);
    }

}
